/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BankParams.java
 *
 * Created on May 22, 2009, 2:59:44 PM
 */

package viewer.mortgage;
import Bank.LendingPolicy;
import Bank.Bank;
import MortgageCore.*;
import javax.swing.*;

/**
 *
 * @author karakots
 */
public class BankParams extends javax.swing.JFrame {

    private Bank bank;
    private SpinnerNumberModel loanInterestModel;
    private SpinnerNumberModel savingsInterestModel;
    private SpinnerNumberModel loanPointsModel;
    private SpinnerNumberModel downPaymentModel;
    private SpinnerNumberModel minLoanModel;
    private SpinnerNumberModel maxLoanModel;
    private SpinnerNumberModel maxPaymentToIncomeModel;

    private double modifiedSavingsInterestRate;
    boolean paramsChanged = false;


    /** Creates new form BankParams */
    public BankParams() {
        initComponents();
    }

    public void setBank(Bank b) {
        bank = b;
        setupCurrentBankParams();
    }

    void setupCurrentBankParams() {
        bankNameText.setText(bank.name);
        LendingPolicy lp = bank.getLendingPolicy();
        // auto adjust
        autoAdjustCheckbox.setSelected(lp.getAdaptive());

        // loan duration
        loanLen15Checkbox.setSelected(lp.loanLength15years);
        loanLen30Checkbox.setSelected(lp.loanLength30years);
        // must have at least one selected

        // loan interest
        double dbVal1 = lp.monthlyMortgageInterestRate*12 + .00005;
        int intVal = (int) (10000 * dbVal1);
        double dblVal = ((double) intVal) /100;
        loanInterestModel = new SpinnerNumberModel(dblVal,0,99,0.01);
        loanInterestRateSpinner.setModel(loanInterestModel);

        // savings interest
        dbVal1 = bank.getSavingsMonthlyInterestRate()*12 + .00005;
        intVal = (int) (10000 * dbVal1);
        dblVal = ((double) intVal) /100;
        savingsInterestModel = new SpinnerNumberModel(dblVal,0,99,0.01);
        savingsInterestRateSpinner.setModel(savingsInterestModel);
        modifiedSavingsInterestRate = bank.getSavingsMonthlyInterestRate();

        // loan points
        dbVal1 = lp.mortgagePoints + .00005;
        intVal = (int) (10000 * dbVal1);
        dblVal = ((double) intVal) /100;
        loanPointsModel = new SpinnerNumberModel(dblVal,0,99,0.01);
        loanPointsSpinner.setModel(loanPointsModel);

        // minimum down payment
        intVal = (int) (100 * lp.minMortgagePctDown);
        downPaymentModel = new SpinnerNumberModel(intVal,0,99,1);
        minDownPaymentSpinner.setModel(downPaymentModel);

        // minimum loan size
        int minVal = (int) (lp.minLoanSize / 1000);
        int maxVal = (int) (lp.maxLoanSize / 1000);
        minLoanModel = new SpinnerNumberModel(minVal,0,maxVal,10);
        minLoanSizeSpinner.setModel(minLoanModel);
        // must be smaller than maximum

        // maximum loan size
        maxLoanModel = new SpinnerNumberModel(maxVal,minVal,10000,10);
        maxLoanSizeSpinner.setModel(maxLoanModel);
        // must be larger than minimum

        // maximum payment to income
        intVal = (int) (100 * lp.maxPaymentToIncome);
        maxPaymentToIncomeModel = new SpinnerNumberModel(intVal,0,99,1);
        maxPaymentToIncomeSpinner.setModel(maxPaymentToIncomeModel);
    }

    private void updateBankParams() {
        LendingPolicy lp = bank.getLendingPolicy();
        // auto adjust
        lp.setAdaptive(autoAdjustCheckbox.isSelected());
        // loan duration
        lp.loanLength15years = loanLen15Checkbox.isSelected();
        lp.loanLength30years = loanLen30Checkbox.isSelected();
        // loan interest
        lp.monthlyMortgageInterestRate = loanInterestModel.getNumber().doubleValue() / (12 *100);
        // savings interest
        bank.setSavingsMonthlyInterestRate(savingsInterestModel.getNumber().doubleValue() / (12 *100));
        // loan points
        lp.mortgagePoints = loanPointsModel.getNumber().doubleValue() / 100;
        // minimum down payment
        lp.minMortgagePctDown = downPaymentModel.getNumber().doubleValue() / 100;
        // minimum loan size
        lp.minLoanSize = minLoanModel.getNumber().doubleValue() * 1000;
        // maximum loan size
        lp.maxLoanSize = maxLoanModel.getNumber().doubleValue() * 1000;
        // maximum payment to income
        lp.maxPaymentToIncome = maxPaymentToIncomeModel.getNumber().doubleValue() / 100;
        //bankNameText.setText(bank.name);

        paramsChanged = false;
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bankManagementBorder = new javax.swing.JPanel();
        autoAdjustCheckbox = new javax.swing.JCheckBox();
        loanLen15Checkbox = new javax.swing.JCheckBox();
        loanLen30Checkbox = new javax.swing.JCheckBox();
        savingsInterestRateSpinner = new javax.swing.JSpinner();
        savingsInterestRateLabel = new javax.swing.JLabel();
        loanInterestRateLabel = new javax.swing.JLabel();
        loanInterestRateSpinner = new javax.swing.JSpinner();
        loanInterestRateLabel1 = new javax.swing.JLabel();
        loanPointsSpinner = new javax.swing.JSpinner();
        percentLabel0 = new javax.swing.JLabel();
        percentLabel1 = new javax.swing.JLabel();
        percentLabel2 = new javax.swing.JLabel();
        loanInterestRateLabel2 = new javax.swing.JLabel();
        minDownPaymentSpinner = new javax.swing.JSpinner();
        percentLabel3 = new javax.swing.JLabel();
        loanInterestRateLabel3 = new javax.swing.JLabel();
        minLoanSizeSpinner = new javax.swing.JSpinner();
        dollarsKLabel1 = new javax.swing.JLabel();
        loanInterestRateLabel4 = new javax.swing.JLabel();
        maxLoanSizeSpinner = new javax.swing.JSpinner();
        dollarsKLabel2 = new javax.swing.JLabel();
        percentLabel4 = new javax.swing.JLabel();
        maxPaymentToIncomeSpinner = new javax.swing.JSpinner();
        loanInterestRateLabel5 = new javax.swing.JLabel();
        cancelButton = new javax.swing.JButton();
        acceptButton = new javax.swing.JButton();
        bankNameLabel = new javax.swing.JLabel();
        bankNameText = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        bankManagementBorder.setBorder(javax.swing.BorderFactory.createTitledBorder("Bank Management"));

        autoAdjustCheckbox.setText("Auto-adjust parameters");
        autoAdjustCheckbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                autoAdjustCheckboxActionPerformed(evt);
            }
        });
        autoAdjustCheckbox.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                autoAdjustCheckboxStateChanged(evt);
            }
        });

        loanLen15Checkbox.setText("15 year loans");
        loanLen15Checkbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loanLen15CheckboxActionPerformed(evt);
            }
        });
        loanLen15Checkbox.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                loanLen15CheckboxStateChanged(evt);
            }
        });

        loanLen30Checkbox.setText("30 year loans");
        loanLen30Checkbox.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                loanLen30CheckboxStateChanged(evt);
            }
        });

        savingsInterestRateSpinner.setName("Savings interest rate"); // NOI18N
        savingsInterestRateSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                savingsInterestRateSpinnerStateChanged(evt);
            }
        });

        savingsInterestRateLabel.setText("Savings interest rate");

        loanInterestRateLabel.setText("Loan interest rate");

        loanInterestRateSpinner.setName("Savings interest rate"); // NOI18N
        loanInterestRateSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                loanInterestRateSpinnerStateChanged(evt);
            }
        });

        loanInterestRateLabel1.setText("Loan points");

        loanPointsSpinner.setName("Savings interest rate"); // NOI18N
        loanPointsSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                loanPointsSpinnerStateChanged(evt);
            }
        });

        percentLabel0.setText("%");

        percentLabel1.setText("%");

        percentLabel2.setText("%");

        loanInterestRateLabel2.setText("Minimum down payment");

        minDownPaymentSpinner.setName("Savings interest rate"); // NOI18N
        minDownPaymentSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                minDownPaymentSpinnerStateChanged(evt);
            }
        });

        percentLabel3.setText("%");

        loanInterestRateLabel3.setText("Minimum loan size");

        minLoanSizeSpinner.setName("Savings interest rate"); // NOI18N
        minLoanSizeSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                minLoanSizeSpinnerStateChanged(evt);
            }
        });

        dollarsKLabel1.setText("$K");

        loanInterestRateLabel4.setText("Maximum loan size");

        maxLoanSizeSpinner.setName("Savings interest rate"); // NOI18N
        maxLoanSizeSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                maxLoanSizeSpinnerStateChanged(evt);
            }
        });

        dollarsKLabel2.setText("$K");

        percentLabel4.setText("%");

        maxPaymentToIncomeSpinner.setName("Savings interest rate"); // NOI18N
        maxPaymentToIncomeSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                maxPaymentToIncomeSpinnerStateChanged(evt);
            }
        });

        loanInterestRateLabel5.setText("Maximum Payment:Income");

        cancelButton.setText("Close");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        acceptButton.setText("Apply");
        acceptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                acceptButtonActionPerformed(evt);
            }
        });

        bankNameLabel.setText("Name");

        bankNameText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bankNameTextActionPerformed(evt);
            }
        });
        bankNameText.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                bankNameTextPropertyChange(evt);
            }
        });

        org.jdesktop.layout.GroupLayout bankManagementBorderLayout = new org.jdesktop.layout.GroupLayout(bankManagementBorder);
        bankManagementBorder.setLayout(bankManagementBorderLayout);
        bankManagementBorderLayout.setHorizontalGroup(
            bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(bankManagementBorderLayout.createSequentialGroup()
                .add(10, 10, 10)
                .add(bankNameLabel)
                .add(2, 2, 2)
                .add(bankNameText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 228, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(30, Short.MAX_VALUE))
            .add(bankManagementBorderLayout.createSequentialGroup()
                .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(bankManagementBorderLayout.createSequentialGroup()
                        .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(bankManagementBorderLayout.createSequentialGroup()
                                .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(bankManagementBorderLayout.createSequentialGroup()
                                        .add(31, 31, 31)
                                        .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(org.jdesktop.layout.GroupLayout.TRAILING, loanInterestRateLabel2)
                                            .add(org.jdesktop.layout.GroupLayout.TRAILING, loanInterestRateLabel1)
                                            .add(org.jdesktop.layout.GroupLayout.TRAILING, loanInterestRateLabel)
                                            .add(org.jdesktop.layout.GroupLayout.TRAILING, savingsInterestRateLabel))
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                            .add(minDownPaymentSpinner)
                                            .add(loanPointsSpinner)
                                            .add(savingsInterestRateSpinner)
                                            .add(loanInterestRateSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 68, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                    .add(bankManagementBorderLayout.createSequentialGroup()
                                        .addContainerGap()
                                        .add(loanInterestRateLabel5)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(maxPaymentToIncomeSpinner)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, bankManagementBorderLayout.createSequentialGroup()
                                .addContainerGap()
                                .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(bankManagementBorderLayout.createSequentialGroup()
                                        .add(3, 3, 3)
                                        .add(loanInterestRateLabel3))
                                    .add(loanInterestRateLabel4))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(maxLoanSizeSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 121, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(minLoanSizeSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 121, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                        .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                            .add(percentLabel0)
                            .add(percentLabel1)
                            .add(percentLabel2)
                            .add(percentLabel3)
                            .add(percentLabel4)
                            .add(dollarsKLabel1)
                            .add(dollarsKLabel2)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, bankManagementBorderLayout.createSequentialGroup()
                        .addContainerGap(73, Short.MAX_VALUE)
                        .add(acceptButton)
                        .add(40, 40, 40)
                        .add(cancelButton)
                        .add(18, 18, 18))
                    .add(bankManagementBorderLayout.createSequentialGroup()
                        .add(autoAdjustCheckbox)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(bankManagementBorderLayout.createSequentialGroup()
                        .add(loanLen15Checkbox)
                        .add(18, 18, 18)
                        .add(loanLen30Checkbox)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(16, 16, 16))
        );
        bankManagementBorderLayout.setVerticalGroup(
            bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(bankManagementBorderLayout.createSequentialGroup()
                .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(bankNameLabel)
                    .add(bankNameText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(bankManagementBorderLayout.createSequentialGroup()
                        .add(autoAdjustCheckbox)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(loanLen15Checkbox)
                            .add(loanLen30Checkbox))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                            .add(percentLabel0)
                            .add(savingsInterestRateSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                            .add(percentLabel1)
                            .add(loanInterestRateSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(loanInterestRateLabel)))
                    .add(bankManagementBorderLayout.createSequentialGroup()
                        .add(64, 64, 64)
                        .add(savingsInterestRateLabel)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(bankManagementBorderLayout.createSequentialGroup()
                        .add(6, 6, 6)
                        .add(percentLabel2))
                    .add(bankManagementBorderLayout.createSequentialGroup()
                        .add(6, 6, 6)
                        .add(loanInterestRateLabel1))
                    .add(loanPointsSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(loanInterestRateLabel2)
                    .add(minDownPaymentSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(percentLabel3))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(loanInterestRateLabel5)
                    .add(maxPaymentToIncomeSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(percentLabel4))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(bankManagementBorderLayout.createSequentialGroup()
                        .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(dollarsKLabel1)
                            .add(minLoanSizeSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                            .add(dollarsKLabel2)
                            .add(loanInterestRateLabel4)
                            .add(maxLoanSizeSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(bankManagementBorderLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(cancelButton)
                            .add(acceptButton)))
                    .add(loanInterestRateLabel3))
                .addContainerGap(8, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(bankManagementBorder, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(bankManagementBorder, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 406, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void autoAdjustCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoAdjustCheckboxActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_autoAdjustCheckboxActionPerformed

    private void loanLen15CheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loanLen15CheckboxActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_loanLen15CheckboxActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        setVisible(false);
        bank.paramViewOpen = false;
        dispose();
}//GEN-LAST:event_cancelButtonActionPerformed

    private void acceptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptButtonActionPerformed
        bank.setName(bankNameText.getText());
        setTitle(bank.name);
        if (paramsChanged)
            updateBankParams();
}//GEN-LAST:event_acceptButtonActionPerformed

    private void loanLen15CheckboxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_loanLen15CheckboxStateChanged
        paramsChanged = true;
    }//GEN-LAST:event_loanLen15CheckboxStateChanged

    private void loanLen30CheckboxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_loanLen30CheckboxStateChanged
        paramsChanged = true;
    }//GEN-LAST:event_loanLen30CheckboxStateChanged

    private void savingsInterestRateSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_savingsInterestRateSpinnerStateChanged
        paramsChanged = true;
    }//GEN-LAST:event_savingsInterestRateSpinnerStateChanged

    private void loanPointsSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_loanPointsSpinnerStateChanged
        paramsChanged = true;
    }//GEN-LAST:event_loanPointsSpinnerStateChanged

    private void loanInterestRateSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_loanInterestRateSpinnerStateChanged
        paramsChanged = true;
    }//GEN-LAST:event_loanInterestRateSpinnerStateChanged

    private void minDownPaymentSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_minDownPaymentSpinnerStateChanged
        paramsChanged = true;
    }//GEN-LAST:event_minDownPaymentSpinnerStateChanged

    private void maxPaymentToIncomeSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_maxPaymentToIncomeSpinnerStateChanged
        paramsChanged = true;
    }//GEN-LAST:event_maxPaymentToIncomeSpinnerStateChanged

    private void minLoanSizeSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_minLoanSizeSpinnerStateChanged
        paramsChanged = true;
        double maxLoanModelVal = maxLoanModel.getNumber().doubleValue();
        if (minLoanModel.getNumber().doubleValue() >= maxLoanModelVal) {
            minLoanSizeSpinner.setValue(maxLoanModelVal - 1);
        }
    }//GEN-LAST:event_minLoanSizeSpinnerStateChanged

    private void maxLoanSizeSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_maxLoanSizeSpinnerStateChanged
        paramsChanged = true;
        double minLoanModelVal = minLoanModel.getNumber().doubleValue();
        if (maxLoanModel.getNumber().doubleValue() <= minLoanModelVal) {
            maxLoanSizeSpinner.setValue(minLoanModelVal + 1);
        }

    }//GEN-LAST:event_maxLoanSizeSpinnerStateChanged

    private void autoAdjustCheckboxStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_autoAdjustCheckboxStateChanged
        paramsChanged = true;
    }//GEN-LAST:event_autoAdjustCheckboxStateChanged

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        bank.paramViewOpen = false;
    }//GEN-LAST:event_formWindowClosed

    private void bankNameTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bankNameTextActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_bankNameTextActionPerformed

    private void bankNameTextPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_bankNameTextPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_bankNameTextPropertyChange

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new BankParams().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton acceptButton;
    private javax.swing.JCheckBox autoAdjustCheckbox;
    private javax.swing.JPanel bankManagementBorder;
    private javax.swing.JLabel bankNameLabel;
    private javax.swing.JTextField bankNameText;
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel dollarsKLabel1;
    private javax.swing.JLabel dollarsKLabel2;
    private javax.swing.JLabel loanInterestRateLabel;
    private javax.swing.JLabel loanInterestRateLabel1;
    private javax.swing.JLabel loanInterestRateLabel2;
    private javax.swing.JLabel loanInterestRateLabel3;
    private javax.swing.JLabel loanInterestRateLabel4;
    private javax.swing.JLabel loanInterestRateLabel5;
    private javax.swing.JSpinner loanInterestRateSpinner;
    private javax.swing.JCheckBox loanLen15Checkbox;
    private javax.swing.JCheckBox loanLen30Checkbox;
    private javax.swing.JSpinner loanPointsSpinner;
    private javax.swing.JSpinner maxLoanSizeSpinner;
    private javax.swing.JSpinner maxPaymentToIncomeSpinner;
    private javax.swing.JSpinner minDownPaymentSpinner;
    private javax.swing.JSpinner minLoanSizeSpinner;
    private javax.swing.JLabel percentLabel0;
    private javax.swing.JLabel percentLabel1;
    private javax.swing.JLabel percentLabel2;
    private javax.swing.JLabel percentLabel3;
    private javax.swing.JLabel percentLabel4;
    private javax.swing.JLabel savingsInterestRateLabel;
    private javax.swing.JSpinner savingsInterestRateSpinner;
    // End of variables declaration//GEN-END:variables

}
